package com.yun.algorithmproblem.leetcode;

public class Leetcode2241 {

    public static void main(String[] args) {

    }

    class ATM {

        int[] atm;
        int[] atmAmount;
        public ATM() {
            this.atm=new int[5];
            this.atmAmount=new int[]{20,50,100,200,500};
        }

        public void deposit(int[] banknotesCount) {
            for (int i = 0; i < 5; i++) {
                atm[i]+=banknotesCount[i];
            }
        }

        public int[] withdraw(int amount) {
            int[] ans=new int[5];
            int[] atmTemp= atm.clone();
            int i=4;
            while (i>=0){
                int k = amount / atmAmount[i];
                if(atmTemp[i]>0 && atmTemp[i]<=k){
                    amount-=atmAmount[i]*atmTemp[i];
                    ans[i]+=atmTemp[i];
                    atmTemp[i]=0;
                }else if(atmTemp[i]>0 && atmTemp[i]>k){
                    atmTemp[i]-=k;
                    amount-=atmAmount[i]*k;
                    ans[i]+=k;
                }
                i--;
            }
            if(amount==0){
                atm=atmTemp;
                return ans;
            }else {
                return new int[]{-1};
            }
        }
    }
}
